//根据jQuery选择器找到需要加载ystep的容器
//loadStep 方法可以初始化ystep

// 步骤进度条一



// 步骤进度条三
$(".ystep3").loadStep({
    size: "large",
    color: "green",
    steps: [{
        title: "投产",
        content: "负责人：林鹏     审批时间：201705.15     节点状态：已完成  节点时间1天",
    }, {
        title: "预计指标",
        content: "负责人：林鹏     审批时间：201705.15     节点状态：已完成  节点时间1天",
    }]
});

$(".ystep3").setStep(1);

//预警滚动轮播js
var box = document.getElementById("div1"),
    can = true;
box.innerHTML += box.innerHTML;
box.onmouseover = function () {
    can = false
};
box.onmouseout = function () {
    can = true
};
new function () {
    var stop = box.scrollTop % 150 == 0 && !can;
    if (!stop) box.scrollTop == parseInt(box.scrollHeight / 3) ? box.scrollTop = 0 : box.scrollTop++;
    setTimeout(arguments.callee, box.scrollTop % 150 ? 50 : 3000);
};


$(function () {
   //项目总用时
    var projectId = "";
    $.ajax({
        url: "/synthindex/getprojectprogresstime",
        type: "GET",
        dataType: "json", //返回数据形式为json
        contentType: 'application/json;charset=UTF-8',
        data: {projectId:projectId},
        success: function (res) {
            if (res.code == "200") {
            var item = res.data;
            $(".project-time  .larger-font").html(item.useTime);//总用时
                var html ="";
                html = '\<li>\
                            <span></span>\
                            <span class="margin">洽谈开始时间</span>\
                            <span class="margin"> '+item.beginTime+'</span>\
                            <span></span>\
                          </li>\
                        <li>\
                            <span></span>\
                            <span class="margin">在建阶段耗时</span>\
                            <span class="margin">'+item.useTime+'天</span>\
                            <span>\
                                占比'+item.percent+'\
                            </span>\
                       </li>\
                       <li>\
                           <span></span>\
                           <span class="margin">计划投产</span>\
                           <span class="margin">'+item.endTime+'</span>\
                           <span></span>\
                       </li>\
                    ';
                   $(".project-time  .small-legend").html(html);
            } else {
                console.log("系统出错，请联系管理员");
            }
        }
    });

    //领导走访服务
    $.ajax({
        url: "/interview/interviewdetail",
        type: "POST",
        dataType: "json", //返回数据形式为json
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({enterpriseName:""}),
        success: function (res) {
            if (res.code == "200") {
                // console.log(res);
                var item = res.data;
                var html ="";
                html ='\<div class="leader-visit-left">\
                            <h1>县领导走访服务企业情况</h1>\
                            <table>\
                                    <tr>\
                                    <th>基本情况</th>\
                                    </tr>\
                                    <tr>\
                                    <td>企业名称</td>\
                                    <td rowspan="2">'+item.contactBusiness+'</td>\
                                    </tr>\
                                    <tr>\
                                    <td></td>\
                                    <tr>\
                                    <td>挂钩领导</td>\
                                    <td>'+item.userName+'</td>\
                                    </tr>\
                                    <tr>\
                                    <td>当月走访</td>\
                                    <td>'+item.interviewCountThisMonth+'次</td>\
                                </tr>\
                                <tr>\
                                <td>走访日期</td>\
                                <td>'+item.fillDate+'</td>\
                                </tr>\
                             </table>\
                      </div>\
                       <div class="leader-visit-right">\
                             <h3>详细情况</h3>\
                            <div>\
                                <div>挂钩企业面临的问题和困难</div>\
                                <p>\
                               '+item.businessProblem+'\
                                </p>\
                            </div>\
                        <div>\
                        <div>协调解决情况</div>\
                            <p>\
                             '+item.helpExperience+'\
                           </p>\
                        </div>\
                       <div>\
                        <div>协\调解决情况 拷贝</div>\
                                <p>\
                                  '+item.solveState+'\
                                </p>\
                        </div>\
                   </div>\
                    ';
                $(".leader-visit").html(html);

            } else {
                console.log("系统出错，请联系管理员");
            }
        }
    });

    //左上角项目信息进度
    $.ajax({
        url: "/synthindex/getbasesituation",
        type: "POST",
        dataType: "json", //返回数据形式为json
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({projectId:projectId}),
        success: function (res) {
            if (res.code == "200") {
                var item = res.data;
                var html= "";
                    html='\
                    <div class="project-name">\
                        <span>'+item.projectName+'</span>\
                        <span>'+item.projectStage+'</span>\
                    </div>\
                    <div class="company-info clear">\
                       <ul class="clear">\
                          <li class="project-name" >'+item.investorName+'</li>\
                          <li class="responsible-person">'+item.projectManager+'</li>\
                       </ul>\
                   </div>\
                   <ul class="company-tag clear">\
                       <li>'+item.projectClass+'</li>\
                       <li>'+item.attribute+'</li>\
                      <li>'+item.totalInver+'亿</li>\
                   </ul>\
                   ';
                $(".project-content").html(html);

                //进度条一
                $(".ystep1").loadStep({
                    size: "large",
                    color: "green",
                    steps: [{
                        title: "意向",
                        content: "",
                    }, {
                        title: "在谈",
                        content: "",
                    }, {
                        title: "评审",
                        content: "",
                    }, {
                        title: "签约",
                        content: "",
                    }, {
                        title: "落地",
                        content: "",
                    }, {
                        title: "审批",
                        content: "",
                    }]
                });
                var progressLength=0;
                for(var i =  item.progress1.length-1;i>0;i--){
                    if(item.progress1[i].projectState !=  "已完成"){
                        progressLength =  i;
                        continue;
                    }
                    break;
                }
                $(".ystep1").setStep(progressLength);
                //进度条二
                var arr = [];
                for(var i =0;i<item.progress2.length;i++){
                    var obj = {};
                    obj.title=item.progress2[i].stage;
                    obj.content="";
                    arr.push(obj);
                }
                $(".ystep2").loadStep({
                    size: "large",
                    color: "green",
                    steps: arr
                });
                $(".ystep2").setStep(item.progress2.length);


            } else {
                console.log("系统出错，请联系管理员");
            }
        }
    });
    $(".ystep2 .ystep-container-steps li").addClass("hidden-font");

    //项目进度时间表
    $.ajax({
        url: "/synthindex/getprojectschedule",
        type: "GET",
        dataType: "json", //返回数据形式为json
        contentType: 'application/json;charset=UTF-8',
        data: {projectId:projectId},
        success: function (res) {
            if (res.code == "200") {
                var item = res.data;
                $(".stage-info").html("在建阶段总耗时:"+item.countFinishDays + "，超前"+item.earlyFinishedDays +"天");
                projectSchedule(item);
            } else {
                console.log("系统出错，请联系管理员");
            }
        }
    });

    //预警
    $.ajax({
        url: "/earlywarning/getnumbers",
        type: "POST",
        dataType: "json", //返回数据形式为json
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({projectId:20180302100000000182}),
        success: function (res) {
            if (res.code == "200") {
               var item = res.data;
               $(".highly  em").html(item.high);
               $(".moderate  em").html(item.mid);
               $(".lower   em").html(item.low);
               $(".warning-circle  h1").html(item.total);
            } else {
                console.log("系统出错，请联系管理员");
            }
        }
    });


    //点击预警总数
    $(".warning-circle  h1").click(function () {
        $.ajax({
            url: "/earlywarning/getwarningshort",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({projectId:"20180302100000000182"}),
            success: function (res) {
                if (res.code == "200") {
                    var item = res.data;
                    // console.log(res);
                    if(item != undefined){
                        var html="";
                        for(var i =0;i<item.length;i++){
                            html+='\
                            <div class="row no-margin">\
                               <div class="col-xs-3">'+item[i].nodeId+'节点</div>\
                                 <div class="col-xs-6 hidden-font" title="'+item[i].problem+'">'+item[i].problem+'</div>\
                               <div class="col-xs-3" style="padding-right: 0 !important;">'+item[i].nodeTime+'</div>\
                            </div>\
                                ';
                        }
                        $("#div1").html(html);
                    }

                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
    });

    //预警初始化
    $.ajax({
        url: "/earlywarning/getwarningshort",
        type: "POST",
        dataType: "json", //返回数据形式为json
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({projectId:"20180302100000000182"}),
        success: function (res) {
            if (res.code == "200") {
                var item = res.data;
                // console.log(res);
                if(item != undefined){
                    var html="";
                    for(var i =0;i<item.length;i++){
                        html+='\
                            <div class="row no-margin">\
                               <div class="col-xs-3">'+item[i].nodeId+'节点</div>\
                                 <div class="col-xs-6 hidden-font" title="'+item[i].problem+'">'+item[i].problem+'</div>\
                               <div class="col-xs-3" style="padding-right: 0 !important;">'+item[i].nodeTime+'</div>\
                            </div>\
                                ';
                    }
                    $("#div1").html(html);
                }

            } else {
                console.log("系统出错，请联系管理员");
            }
        }
    });

    /**
     * 查看预警节点
     * seeNode(type)  type= 1 =>轻度  1=>中度  3=>高度
     *
     */
    function seeNode(type) {
        $.ajax({
            url: "/earlywarning/getwarningdetail",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({projectId:"20180302100000000182",level:type}),
            success: function (res) {
                if (res.code == "200") {
                    var item = res.data;
                    // console.log(res);
                    if(item != undefined){
                        var html="";
                        for(var i =0;i<item.length;i++){
                            html+='\
                            <div class="row no-margin">\
                               <div class="col-xs-3">'+item[i].nodeId+'节点</div>\
                                 <div class="col-xs-6 hidden-font" title="'+item[i].problem+'">'+item[i].problem+'</div>\
                               <div class="col-xs-3" style="padding-right: 0 !important;">'+item[i].nodeTime+'</div>\
                            </div>\
                                ';
                        }
                        $("#div1").html(html);
                    }

                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
    }

    //点击高度预警事件
    $(".inspector-node>li:nth-child(1)").click(function () {
        seeNode(3);
    });

    //点击中度预警事件
    $(".inspector-node>li:nth-child(2)").click(function () {
        seeNode(2);
    });

    //点击低度预警事件
    $(".inspector-node>li:nth-child(3)").click(function () {
        seeNode(1);
    });

/*    $(".ystep2   .ystep-container-steps  li").hover(function (){
        $(".detail-info").removeClass('hidden');
    },function (){
        $(".detail-info").addClass('hidden');
    });

    $(".ystep1   .ystep-container-steps  li").hover(function (){
        $(".detail-info").removeClass('hidden');
    },function (){
        $(".detail-info").addClass('hidden');
    });*/


});
